<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" id="vp" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<title>童圈</title>
		<link href="../../css/style.css" rel="stylesheet" type="text/css">
		<link href="../../css/mui.min.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="../../src/style.css">
		<link rel="stylesheet" href="../../src/iconfont/iconfont.css">
		<style>
			.swiper-slide img {
				width: 100%;
				height: auto;
			}
			
			.swiper-slide {
				background: #ffffff;
			}
			
			.modelShows {
				width: 100%;
				background-color: rgba(255, 255, 255, 0.43);
				position: fixed;
				left: 0px;
				top: 0px;
				z-index: 1111;
			}
			
			.swiper-slide {
				height: auto;
			}
			
			#banner {
				width: 100%;
				height: 6rem;
				margin: 0 auto;
				position: relative;
				top: 0;
				left: 0;
			}
			
			.operate span {
				font-size: 20px;
				width: 33.33%;
				margin-left: 10px;
			}
			
			.icon-favorfill {
				color: #ff8383;
			}
			
			.icon-likefill {
				color: #ff8383;
			}
			
			.icon-more {
				width: auto!important;
			}
			
			.newMsgTheme {
				position: absolute;
				width: 150px;
				height: 35px;
				padding-top: 10px;
				background: #5d5d5d;
				border-radius: 3px;
				margin-left: 10px;
				word-break: break-word;
				color: white;
				padding: 5px;
				line-height: 25px;
				bottom: -10px;
				right: 40px;
				display: flex;
				flex-wrap: nowrap;
			}
			
			.newMsgTheme::after {
				content: "";
				display: block;
				position: absolute;
				width: 0;
				height: 0;
				border: 8px solid transparent;
				border-right-color: #5d5d5d;
				top: 7px;
				right: -14px;
				transform: rotate(180deg);
			}
			
			#children .redmsgbox {
				background-color: aliceblue;
				border: none;
			}
			
			#children .redmsgbox img {
				width: 30px;
				display: inline-block!important;
				padding: 5px 0;
				float: left;
			}
			
			#children .redmsgbox span {
				line-height: 40px;
				padding-left: 5px;
			}
			
			.videoWidth {
				width: 100%;
			}
			
			.mmm {
				position: fixed;
				bottom: 0px;
				width: 100%;
				height: 200px;
				background-color: #5d5d5d;
				-webkit-overflow-scroll: touch;
			}
			
			.inputssss {}
			
			.modelAlert {
				position: fixed;
				top: 10px;
				left: 0px;
				text-align: center;
				z-index: 2222;
				width: 100%;
			}
			
			.modelAlert embed {
				width: 100px;
				margin-left: auto;
				margin-right: auto;
			}
			
			.icon-more {
				background: #f0f0f0;
				height: 20px;
				padding: 0!important;
				line-height: 20px;
				width: 30px!important;
				text-align: center;
				border-radius: 5px;
			}
			
			.maskbox {
				width: 100%;
				height: 100%;
				position: fixed;
				background: #000;
				opacity: .5;
				top: 0;
				bottom: 0;
				z-index: 99;
				display: none;
			}
		</style>
	</head>

	<body>
		<div id="children">

			<div id="pullrefresh" class="mui-content mui-scroll-wrapper list-frame" style="background: #fff;">

				<div class="mui-scroll">
					<div id="banner">
						<div class="swiper-container">
							<div class="swiper-wrapper"></div>
							<div class="pagination"></div>
						</div>
					</div>

					<div class="newHeader">
						<!-- @tap="sendMsg()" -->
						<div class="sendmsg" id="sendmsg">
							<font class="mui-icon mui-icon-camera"></font>
						</div>
					</div>
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron">
						<template v-for="(item,index) in items" :key="index">
							<li class="list-info-li">
								<div class="main clearfix">
									<div :style="{backgroundImage:'url(' + item.member_avatar + ')'}" class="people-l fl"></div>
									<!--img :src="item.member_avatar" class="people-l fl" /-->
									<div class="list-info-li-r fl">
										<div class="name posir">
											<div class="name-text">{{item.member_name}}</div>
										</div>
										<!--消息内容-->
										<div class="text-info" id="text-info">
											<p class="text overhide word-long fold">{{item.content}}</p>
											<p class="all" v-if="item.content.length>95" @click="handleFold($event)" onclick="javascript:this.innerHTML=(this.innerHTML=='全文'?'收起':'全文')">全文</p>
										</div>
										<!--1.单图-->
										<div class="list-info-pic" v-if="item.type==1">
											<img :src="item.message_image" class="imgWidth" @tap="previewimg(item.message_image,0)" />
										</div>
										<!--2.多图-->
										<div class="list-info-pic clearfix" v-if="item.type==2">
											<div :style="{backgroundImage:'url(' + pic + ')'}" class="list-ip-img2 list-info-picBackground fl" v-for="(pic,index) in item.message_image" @tap="previewimg(item.message_image,index)"></div>
										</div>
										<!--3.视频-->
										<div class="clearfix clearfixvideo" v-if="item.type==3"> 
											<video :src="item.video" class="videoWidth" :poster="item.videoimg" type="video/mp4" ></video> 
											<div class="playbtn"><img src="../../images/play.png" /></div>
										</div>
										<!--4.图文-->
										<div class="list-info-li-tuwen clearfix" v-if="item.type==4" @tap="open_detail(item.link,item.title)">
											<div class="list-info-li-tuwenBackground" :style="{backgroundImage:'url(' + item.pic + ')'}"></div>
											<div class="list-info-li-tuwenContent fl">
												<div><span :class="item.title.length>18 ? 'p1' : 'p2' ">{{item.title}}</span></div>
											</div>
										</div>
										<!--5.其他-->
										<div class="list-info-pic clearfix" v-if="item.type==5">
										</div>
										<!--操作按钮-->
										<div class="fabulous clearfix">
											<div class="text fl"><span class="fl">{{item.ftime}}</span><span v-if="item.member_id==item.uid" class="trash fl" @tap.stop="delmsg(item,index)" />删除</span>
											</div>
											<div class="operate fr" style="display: flex;flex-wrap: nowrap; position: relative;">
												<div class="newMsgTheme" v-show="item.show">
													<span :data-index="index" class="iconfont" @tap="setupvote($event,item)" v-bind:class="[item.upvote_status==0?'icon-like':'icon-likefill']"></span>
													<span :data-index="index" class="iconfont icon-comment" @tap="commenta($event,item)"></span>
													<span :data-index="index" class="iconfont" @tap="savetofav($event,item)" v-bind:class="[item.coll==0?'icon-favor':'icon-favorfill']"></span>
												</div>
												<span class="iconfont icon-more" @tap="get(event)" :data-index="index"></span>
											</div>
										</div>
										<div class="pinglun">
											<div class="dianzan" v-if="item.upvote_count!=0">
												<img src="../../images/icon/xin_3.png" class="xintu fl" />
												<div class="zannameBox">
													<span v-for="(zan,index) in item.upvote">{{zan.member_name}}<span v-if="item.upvote_count>5 ? index<4 : index<item.upvote_count-1">,</span></span>
												</div>

												<!-- <div class="clear"></div> -->
												<!-- <div class="zancounta" v-if="item.upvote_count>5"  @tap="commentContent(item)">...等{{item.upvote_count}}人觉得很赞</div>  -->
												<div class="zancounta" style="font-size: 12px;" @tap="commentContent(item)">...等{{item.upvote_count}}人觉得很赞</div>
												<!-- <div class="clear"></div> -->
											</div>

											<div class="pinglunCo">
												<div class="pinglunBoxb" v-for="(comment,index) in item.comment" v-if="index<5">
													<div>
														<span class="pinglunname">{{comment.member_name}}</span><span class="maohao">:</span><span class="pinglunCoten">{{comment.comment_content}}</span><span v-if="comment.member_id==item.uid" class="delComment" @tap="delcomment(item,comment,event)">删除</span>
														<div class="clear"></div>
													</div>
												</div>
											</div>
											<div v-if="item.comment_count>5" class="morez" @tap="commentContent(item)">更多...</div>
											<div class="clear"></div>
										</div>
									</div>

							</li>
						</template>

					</ul>
					</div>
				</div>
				<div v-show="modelShow" class="msgInput" style="bottom: 0px; position:fixed; z-index: 9;">
					<input v-model="msgValue" type="text" id="msgText" placeholder="评论">
					<a href="#" @tap="put($event)">{{msgbtntext}}</a>
				</div> 
			</div>
			<script type="text/javascript" src="../../js/jquery-1.11.3.js"></script>
			<script src="../../js/mui.js"></script>
			<script src="../../js/idangerous.swiper.min.js"></script>
			<script src="../../js/vue.min.js"></script>
			<script src="../../js/app.js"></script>
			<script src="../../js/iconfont.js"></script>
			

			<script>
				var deceleration = mui.os.ios ? 0.003 : 0.0009;
				mui('.mui-scroll-wrapper').scroll({
					scrollY: true, //是否竖向滚动
					scrollX: false, //是否横向滚动 
					startX: 0, //初始化时滚动至x
					startY: 0, //初始化时滚动至y
					indicators: false, //是否显示滚动条
					deceleration: deceleration, //阻尼系数,系数越小滑动越灵敏
					bounce: false, //是否启用回弹
				});
				var pages = 1;
				var state = "";
				var operateStatus = 1; //防止点赞收藏等操作太快
				mui.init({
					gestureConfig: {
						doubletap: true,
						longtap: true, //默认为false 
						click: true
					},
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							callback: function() {
								pages = 1
								pulldownRefresh(pages)
							}
						},
						up: {
							contentrefresh: '正在加载...',
							callback: function() {
								pages++;
								pullupRefresh(pages)
							}
						}
					}
				});

				var pullrefresh = new Vue({
					el: '#children',
					data: {
						items: [], //列表信息流数据
						fold: true,
						showss: false,
						clickTf: true,
						activeindex: 0,
						commentcontent: [],
						newmsg: [],
						winHeight: window.innerHeight,
						winHeights: window.innerHeight,
						modelShow: false,
						msgValue: "",
						msgids: "",
						modelShows: false,
						msgbtntext: "发布",
						modelAlert: false,
						bottomText: false,

					},
					methods: {
						focus: function(e) {
							$(".msgInput").css("bottom", '100');

						},
						get: function(e) {
							console.log(e.target.dataset.index)
							$('.newMsgTheme').hide()
							if(pullrefresh.items[e.target.dataset.index].show == true) {
								pullrefresh.items[e.target.dataset.index].show = false
							} else {
								pullrefresh.items[e.target.dataset.index].show = true
							}
							pullrefresh.$forceUpdate();
						},
						closeModelShows() {
							pullrefresh.modelShows = false
						},
						closeModel: function() {
							pullrefresh.modelShow = false
						},
						put: function(event) {
							$("#msgText").blur();
							event.stopPropagation();
							console.log("asdf")
							console.log(pullrefresh.msgValue)
							var commentvalue = pullrefresh.msgValue
							if(commentvalue.trim() == "") {
								alert('请输入评论内容')
								return;
							};
							if(commentvalue.length > 200) {
								alert('请评论小于200个字数');
							} else {
								pullrefresh.msgbtntext = "发布中..."
								pullrefresh.modelShow = false;
								mui.post(Apiurl + 'index/comment', {
									uid: state.userid,
									id: pullrefresh.msgids,
									content: pullrefresh.msgValue,
									memberToken: memberToken,
									child_id: childid
								}, function(data) {

									//alert(JSON.stringify(data))
									if(data.status == 200) {
										var points=''
										if(data.point){
											points='恭喜您获得'+data.point+"积分"
										}
										plus.nativeUI.toast('评论成功'+points, {
											verticalAlign: 'middle'
										});
										for(var i = 0; i < pullrefresh.items.length; i++) {

											if(pullrefresh.items[i].id == pullrefresh.msgids) {
												pullrefresh.items[i].comment = data.comment;
												/*children.items[i].comment_count = data.comment_count; 
												children.items[i].comment_content = data.comment_content; */
											}
										}
										pullrefresh.msgbtntext = "发布";
										pullrefresh.msgValue = "";

										pullrefresh.winHeights = pullrefresh.winHeight;
										/*let dd = {
										    uid: state.userid,
										    memberToken: memberToken
										}
										mui.post(Apiurl + 'index/message_list', dd, function(res) {
										    console.log(res)
										    children.items = convert(res.message)
										    children.msgValue = ""
										    children.modelShow = false
										}, 'json'); 
                                
										children.winHeights = children.winHeight*/
									} else if(data.status == 404) {
										plus.nativeUI.toast('您的输入包含敏感词汇', {
											verticalAlign: 'middle'
										});
										pullrefresh.msgValue = ""
										pullrefresh.msgbtntext = "发布"
										pullrefresh.winHeights = pullrefresh.winHeight

									} else if(data.status == 405) {
										plus.nativeUI.toast('评论异常', {
											verticalAlign: 'middle'
										});
										pullrefresh.msgValue = ""
										pullrefresh.msgbtntext = "发布"
										pullrefresh.winHeights = pullrefresh.winHeight

									}
								}, 'json')

							}
						},
						//发布信息
						sendMsg: function() {
							pullrefresh.modelShows = true
							// if (mui.os.plus) {
							//     var a = [{
							//         title: "视频"
							//     }, {
							//         title: "图片"
							//     }];
							//     plus.nativeUI.actionSheet({
							//         title: "发布类型",
							//         cancel: "取消",
							//         buttons: a
							//     }, function(b) {
							//         switch (b.index) {
							//             case 0:
							//                 break;
							//             case 1:
							//                 pause();
							//                 mui.openWindowWithTitle({
							//                     url: './sendvideo.html',
							//                     id: 'sendmoment',
							//                     preload: true,
							//                     extras: {
							//                         msgtype: '4',
							//                     },
							//                     show: {
							//                         aniShow: 'pop-in',
							//                         autoShow: true
							//                     },
							//                     waiting: {
							//                         autoShow: true
							//                     }
							//                 })
							//                 break;
							//             case 2:
							//                 pause();
							//                 mui.openWindowWithTitle({
							//                     url: './sendmsg.html',
							//                     id: 'sendmoment',
							//                     preload: true,
							//                     extras: {
							//                         msgtype: '4',
							//                     },
							//                     show: {
							//                         aniShow: 'pop-in',
							//                         autoShow: true
							//                     },
							//                     waiting: {
							//                         autoShow: true
							//                     }
							//                 })
							//                 break;
							//             default:
							//                 break
							//         }
							//     })
							// }
						},
						newmsgchange: function() {
							//点击我的未读消息后，清除底部数字提示和顶部提示框
							document.getElementById('noreadmsg').style.display = 'none';
							var mainPage = plus.webview.getWebviewById('main');
							mui.fire(mainPage, 'refreshmymsgnum', {});
							//设置新页面标题
							mui.openWindow({
								url: './mymsg.html',
								id: 'moments_mymsg',
								preload: true,
								show: {
									aniShow: 'pop-in',
									autoShow: true
								},
								styles: {
									"render": "always",
									"popGesture": "hide",
									"bounce": "vertical",
									"bounceBackground": "#efeff4",
									"titleNView": { //详情页原生导航配置
										backgroundColor: '#fff', //导航栏背景色
										titleText: '我的新消息', //导航栏标题
										titleColor: '#000', //文字颜色
										autoBackButton: true, //自动绘制返回箭头
										splitLine: { //底部分割线
											color: '#DFDFDF'
										}
									}
								},
								waiting: {
									autoShow: true
								}
							});
						},
						//评论点赞详情
						commentContent: function(item) {
							pause();
							titlestyle.titleNView.titleText = "消息详情";
							mui.openWindow({
								url: './detail.html',
								id: 'moments_detail',
								preload: true,
								extras: {
									messageid: item.id
								},
								show: {
									aniShow: 'pop-in',
									autoShow: true
								},
								styles: titlestyle,
								waiting: {
									autoShow: true
								}
							});
						},
						//删除消息
						delmsg: function(item, index) {
							var data = {
								uid: state.userid,
								message_id: item.id,
								memberToken: memberToken
							};
							that = this;
							var btnArray = ['否', '是'];
							mui.confirm('您是否要删除该条信息？', '删除确认', btnArray, function(e) {

								if(e.index == 1) {
									mui.post(Apiurl + 'index/messagedel', data, function(data) {
										if(data.status == "200") {
											that.items.splice(index, 1);
										}
									}, 'json');
								}
							})
						},
						commenta: function(e, item) {
							e.stopPropagation();
							setTimeout(function() {
								try {
									document.getElementById('msgText').focus();
								} catch(e) {}
							}, 200);
							//let _slef = pullrefresh
							//_slef.winHeights = _slef.winHeight-60
							pullrefresh.modelShow = true;
							console.log(item.id);
							pullrefresh.msgids = item.id
							console.log("asdf")
							console.log(e.target.dataset.index)
							if(pullrefresh.items[e.target.dataset.index].show == true) {
								pullrefresh.items[e.target.dataset.index].show = false
							} else {
								pullrefresh.items[e.target.dataset.index].show = true
							}
							pullrefresh.$forceUpdate();

							/*document.getElementById('inputBox').style.display = 'block';
							document.getElementById("inputa").value="";
							document.getElementById('inputa').focus();
							currItem = item;*/
							// titlestyle.titleNView.titleText = "消息详情";

							// mui.openWindow({
							//     url: 'detail.html',
							//     id: 'commentCon',
							//     preload: true,
							//     extras: {
							//         messageid: item.id
							//     },
							//     show: {
							//         aniShow: 'pop-in',
							//         autoShow: true
							//     },
							//     styles: titlestyle,
							//     waiting: {
							//         autoShow: true
							//     }
							// });

						},
						//删除评论
						delcomment: function(item, comment, event) {
							console.log();
							var data = {
								uid: state.userid,
								id: comment.comment_id,
								memberToken: memberToken
							};
							that = this;
							var btnArray = ['否', '是'];
							mui.confirm('您是否要删除该条评论？', '删除确认', btnArray, function(e) {
								if(e.index == 1) {
									mui.post(Apiurl + 'index/delcomment', data, function(res) {
										if(res.status == "200") {
											item.comment = res.comment;
											item.comment_count = res.comment_count;
											item.comment_content = res.comment_ccontent;
											plus.nativeUI.toast('删除成功', {
												verticalAlign: 'middle'
											});
										}
									}, 'json');
								}
							})
						},
						//图片预览
						previewimg: function(item, index) {

							var urls = [];
							item.forEach(function(img) {
								urls.push(img);
							});

							plus.nativeUI.previewImage(urls, {
								current: index,
								loop: true,
								indicator: 'number'
							});
						},
						//全文/收起
						handleFold: function(e) {
							if(e.target.previousElementSibling.getAttribute('class') == 'text overhide word-long fold') {
								e.target.previousElementSibling.setAttribute('class', 'text overhide word-long unfold')
							} else {
								e.target.previousElementSibling.setAttribute('class', 'text overhide word-long fold')
							}

						},
						//点赞
						setupvote: function(e, item) {

							var data = {
								uid: state.userid,
								id: item.id,
								memberToken: memberToken,
								child_id:childid
							};
							if(item.upvote_status == '1') {
								item.upvote_status = '0';
							} else if(item.upvote_status == '0') {
								item.upvote_status = '1';
							}
							mui.post(Apiurl + 'index/upvote', data, function(data) {
								console.log(JSON.stringify(data));
								if(data.point){
									mui.toast("恭喜您获得"+data.point+'积分')
								}
								if(data.upvote_status == "0") {
									item.upvote = data.upvote;
									item.upvote_count = data.upvote_count;
								}
								if(data.upvote_status == "1") {
									item.upvote = data.upvote;
									item.upvote_count = data.upvote_count;
								}
							}, 'json');

							console.log(e.target.dataset.index)
							if(pullrefresh.items[e.target.dataset.index].show == true) {
								pullrefresh.items[e.target.dataset.index].show = false
							} else {
								pullrefresh.items[e.target.dataset.index].show = true
							}
							pullrefresh.$forceUpdate();

						},
						//收藏
						savetofav: function(e, item) {
							if(operateStatus == 0) return;
							operateStatus = 0; //避免狂点
							var data = {
								uid: state.userid,
								message_id: item.id,
								memberToken: memberToken
							};
							if(e.srcElement.getAttribute('src') == '../../images/icon/fav_0.png') {
								e.srcElement.setAttribute('src', '../../images/icon/fav_1.png');
								setTimeout(function() {
									operateStatus = 1;
								}, 1000);
							} else {
								e.srcElement.setAttribute('src', '../../images/icon/fav_0.png');
								setTimeout(function() {
									operateStatus = 1;
								}, 1000);
							}
							mui.post(Apiurl + 'index/coll', data, function(data) {
								console.log(JSON.stringify(data));
								if(data.coll == "1") {
									item.coll = 1

									plus.nativeUI.toast('收藏成功', {
										verticalAlign: 'middle'
									});
									console.log(e.target.dataset.index)
									if(pullrefresh.items[e.target.dataset.index].show == true) {
										pullrefresh.items[e.target.dataset.index].show = false
									} else {
										pullrefresh.items[e.target.dataset.index].show = true
									}
									pullrefresh.$forceUpdate();
									setTimeout(function() {
										operateStatus = 1;
									}, 1000);
								}
								if(data.coll == "0") {
									item.coll = 0

									plus.nativeUI.toast('取消收藏', {
										verticalAlign: 'middle'
									});
									setTimeout(function() {
										operateStatus = 1;
									}, 1000);
								}
							}, 'json');
						},
					},
				})
				
				
				mui.plusReady(function() {
					
					mui('body').on('tap','.playbtn',function(){
						
						if(mui.os.android){
		                	this.previousElementSibling.webkitRequestFullScreen()
		                }
		                this.previousElementSibling.play();
					});
					state = app.getState();
					memberToken = state.memberToken;
					childid=state.childid;
					//alert(childid)  
					console.log(memberToken)
					data = {
						uid: state.userid,
						memberToken: memberToken,
						page: pages,
						child_id:childid
					};
					//alert(JSON.stringify(data))
					mui.post(Apiurl + 'index/banner', {
						uid: state.userid,
						memberToken: memberToken,
						type:1
					}, function(data) {
						var bannerHtml = "";
						for(var i = 0; i < data.length; i++) {
							bannerHtml += "<div class=\"swiper-slide\" onclick=\"open_detail('" + data[i].banner_url + "','" + data[i].banner_title + "');\"><img src='" + data[i].banner_pic + "'></div>";
						}
						$(".swiper-wrapper").html(bannerHtml);
						var mySwiper = new Swiper('.swiper-container', {
							loop: true,
							pagination: '.pagination',
							paginationClickable: true,
							moveStartThreshold: 100,
							centeredSlides: true,
							autoplay: 3500,
							autoplayDisableOnInteraction: false
						})
					}, 'json');
					var newArray = []
					mui.post(Apiurl + 'index/message_list_new', data, function(data) {
						console.log(data)
						if(data.message && data.message.length > 0) {
							newArray = data.message
							for(var i = 0; i < data.message.length; i++) {
								console.log(newArray[i].id)
								newArray[i].show = false
							}
							pullrefresh.items = convert(newArray)
							console.log(JSON.stringify(newArray))

						}
						// mui('#banner').pullRefresh().endPulldownToRefresh();
					}, 'json');

				})
				bfscrolltop = document.body.scrollTop; //获取软键盘唤起前浏览器滚动部分的高度
				$("#msgText").focus(function() { //在这里‘input.inputframe’是我的底部输入栏的输入框，当它获取焦点时触发事件
					intimer=setInterval(function() { //设置一个计时器，时间设置与软键盘弹出所需时间相近
						document.body.scrollTop = document.body.scrollHeight; //获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
					}, 100)
				}).blur(function() { //设定输入框失去焦点时的事件
					//alert(intimer)
					clearInterval(intimer); //清除计时器
					document.body.scrollTop = bfscrolltop; //将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
				});
				document.getElementsByTagName('body')[0].addEventListener('tap', function() {
					//$("#msgText").blur();
					if($('#msgText').val() != '') {
						var btnArray = ['否', '是'];
						mui.confirm('您是否要取消发送这条评论？', '取消本条评论', btnArray, function(e) {
							if(e.index == 1) {
								pullrefresh.msgValue = ""
								setTimeout(function() {
									pullrefresh.modelShow = false;
									//pullrefresh.winHeights = pullrefresh.winHeight;
								}, 300)
							}
						})
					} else {
						//document.body.scrollTop = bfscrolltop;//将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
						setTimeout(function() {
							pullrefresh.modelShow = false;
							//pullrefresh.winHeights = pullrefresh.winHeight;
						}, 300)
					}
				})
				document.getElementById('msgText').addEventListener('tap', function() {
					event.stopPropagation();
				})
				//解决第三方软键盘唤起时底部input输入框被遮挡问题

				//下拉刷新
				function pulldownRefresh(pages) {

					if(window.plus && plus.networkinfo.getCurrentType() === plus.networkinfo.CONNECTION_NONE) {
						plus.nativeUI.toast('似乎已断开与互联网的连接', {
							verticalAlign: 'top'
						});
						return;
					}
					data.page = pages
					
					//获取消息列表   
					var newArray = []
					mui.post(Apiurl + 'index/message_list_new', data, function(data) {
						console.log(JSON.stringify(data))
						pageaa = data.pagecount;
						if(data.message && data.message.length > 0) {
							newArray = data.message
							for(var i = 0; i < data.message.length; i++) {
								console.log(newArray[i].id)
								newArray[i].show = false
							}
							pullrefresh.items = convert(newArray)
							console.log(JSON.stringify(newArray))

							pullrefresh.modelAlert = false
						}
						mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					}, 'json');
					/*mui.post(Apiurl + 'index/pinglun', data, function(data) {
						children.newmsg = data;
						if(data.count != 0) {
							document.getElementById('noreadmsg').style.display = 'block';
						} else if(data.count == 0) {
							document.getElementById('noreadmsg').style.display = 'none';
						}
					}, 'json')*/
				}
				//上拉加载
				function pullupRefresh(pages) {
					data.page = pages;
					//请求历史列表信息流
					mui.post(Apiurl + 'index/message_list_new', data, function(data) {

						if(pages <= data.pagecount) {
							if(data.message && data.message.length > 0) {
								pullrefresh.items = pullrefresh.items.concat(convert(data.message));
							}
						}

						mui('#pullrefresh').pullRefresh().endPullupToRefresh();
					}, 'json');

				}

				function convert(items) {
					var newItems = [];
					items.forEach(function(item) {
						newItems.push({
							uid: state.userid,
							id: item.id,
							member_avatar: item.member_avatar,
							member_name: item.member_name,
							member_id: item.member_id,
							message_image: item.message_image,
							pic: item.pic,
							title: item.title,
							content: item.content,
							link: item.link,
							coll: item.coll,
							type: item.type,
							ftime: item.ftime,
							upvote_count: item.upvote_count,
							upvote: item.upvote,
							upvote_status: item.upvote_status,
							comment: item.comment,
							video: item.video,
							comment_count: item.comment_count,
							videoimg: item.videoimg,
							show: false

						});
					});
					return newItems;
				}
				var doms = document.getElementById('sendmsg')
				doms.addEventListener("longtap", function() {
					//console.log("你正在向左滑动");
					mui.openWindowWithTitle({
						url: './sendvideo.html',
						id: 'sendmoment',
						preload: true,
						extras: {
							msgtype: '4',
							childid: childid
						},
						show: {
							aniShow: 'pop-in',
							autoShow: true
						},
						waiting: {
							autoShow: true
						}
					})
				});
				doms.addEventListener("tap", function() {
					mui.openWindowWithTitle({
						url: './sendmsg.html',
						id: 'sendmoment',
						preload: true,
						extras: {
							msgtype: '4',
							childid: childid
						},
						show: {
							aniShow: 'pop-in',
							autoShow: true
						},
						waiting: {
							autoShow: true
						}
					})
				})
				//刷新评论内容，避免因为消息详情删除评论后，首页没删除
				window.addEventListener('refreshmomentmsg', function(event) {
					data.child_id = event.detail.changeaa;
					//alert(event.detail.changeaa);
					pulldownRefresh(pages); 
				});
				window.addEventListener('refreshvideo', function(event) {
					pullrefresh.modelShows = false
					pause();
				});

				window.addEventListener('refreshmomentcoll', function(event) {
					var msgid = event.detail.msgid;
					pullrefresh.items.forEach(function(item) {
						if(item.id == msgid) {
							item.coll = 0; 
						}
					})
				});
				window.addEventListener('refreshmomentcomment', function(event) {
					var msgid = event.detail.msgid;
					var data = {
						uid: state.userid,
						id: msgid,
						memberToken: memberToken
					};
					mui.post(Apiurl + 'index/message_info', data, function(res) {
						console.log(res)
						if(res.message && res.message.length > 0) {
							pullrefresh.items.forEach(function(item) {
								res.message.forEach(function(res) {
									console.log(res)
									if(item.id == res.id) {
										item.comment = res.comment;
									}
								})
							});
						}
					}, 'json');
				});
				//切换孩子
				/*window.addEventListener('changeChild', function(event) {
					window.location.reload()
				});*/ 
			</script>
	</body>

</html>